package com.woniu.controller;

import com.woniu.entity.Students;
import com.woniu.service.StudentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @author 杨光 微信号:tolryg
 * @time 15:15
 */
@RestController
@CrossOrigin
public class StudentsController {


    @Autowired
    private StudentsService studentService;

    @RequestMapping("findAllStudents")
    public List<Students> findAllStudents(){
        return studentService.findAllStudents();
    }




    @RequestMapping("addStudent")
    public void addStudent(MultipartFile file) throws IOException {

        System.out.println(file.getOriginalFilename());//打印文件名字

        studentService.addStudent(file);
    }



    @RequestMapping("saveStudents")
    public boolean saveStudents(@RequestBody List<Students> list){
//        Alt + Enter
        return studentService.saveStudents(list);
    }
}
